<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=\, initial-scale=1.0" />
    <title>Document</title>
    <style>
      button.active{
        color: red;
        background-color: #fff;
      }
      .content{
        width: 200px;
        height: 200px;
        border: 1px solid #ccc;
        text-align: center;
        line-height: 200px;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <button
        v-for="(title, index) in tabContent.title"

        @click="switchTab(index)" 
        :class="{active: activeIndex===index}">{{title}}</button>
      
      <div 
        v-for="(content, index) in tabContent.content"
        v-show="activeIndex===index"
        class="content">{{content}}</div>
      
    </div>
    <script src="./vue.global.js"></script>
    <script>
      const { createApp } = Vue;
      const app = createApp({
        data() {
          return {
            activeIndex: 0,
            tabContent: {
              title: ['标题1','标题2','标题3','标题4'],
              content: ['内容1','内容2','内容3','内容4']
            }
          };
        },
        methods: {
          switchTab(index) {
            this.activeIndex = index;
          }
        },
      });
      app.mount("#app");
    </script>
  </body>
</html>
